#ifndef DISK_SIMULATOR_H
#define DISK_SIMULATOR_H

#include <cstddef>
#include <cstdint>

#ifdef __cplusplus
extern "C" {
#endif

// C接口声明
void* disk_create(const char* file_path, std::size_t size_bytes);
void  disk_destroy(void* disk);
int   disk_power_on(void* disk);
int   disk_power_off(void* disk);
int   disk_is_powered_on(void* disk);
std::size_t disk_get_size(void* disk);
int   disk_read(void* disk, std::size_t offset, void* buf, std::size_t len);
int   disk_write(void* disk, std::size_t offset, const void* buf, std::size_t len);

// 新增磁盘信息查询接口
int   disk_get_serial_number(void* disk, char* sn, std::size_t sn_len);
int   disk_get_manufacturer(void* disk, char* manufacturer, std::size_t manufacturer_len);
int   disk_get_model(void* disk, char* model, std::size_t model_len);
int   disk_get_firmware_version(void* disk, char* firmware, std::size_t firmware_len);
int   disk_set_serial_number(void* disk, const char* sn);
int   disk_set_manufacturer(void* disk, const char* manufacturer);
int   disk_set_model(void* disk, const char* model);
int   disk_set_firmware_version(void* disk, const char* firmware);

// 新增SMART信息查询接口
int   disk_get_smart_attribute(void* disk, int attribute_id, int* current, int* worst, int* threshold, int* raw_value);
int   disk_set_smart_attribute(void* disk, int attribute_id, int current, int worst, int threshold, int raw_value);
int   disk_get_smart_status(void* disk, int* overall_status);
int   disk_get_smart_temperature(void* disk, int* temperature);
int   disk_get_smart_power_on_hours(void* disk, int* hours);
int   disk_get_smart_reallocated_sectors(void* disk, int* count);

#ifdef __cplusplus
}
#endif

// C++磁盘模拟器类
class DiskSimulator {
public:
    DiskSimulator(const char* file_path, std::size_t size_bytes);
    ~DiskSimulator();
    int power_on();
    int power_off();
    bool is_powered_on() const;
    std::size_t get_size() const;
    int read(std::size_t offset, void* buf, std::size_t len);
    int write(std::size_t offset, const void* buf, std::size_t len);
    
    // 新增磁盘信息查询方法
    int get_serial_number(char* sn, std::size_t sn_len) const;
    int get_manufacturer(char* manufacturer, std::size_t manufacturer_len) const;
    int get_model(char* model, std::size_t model_len) const;
    int get_firmware_version(char* firmware, std::size_t firmware_len) const;
    int set_serial_number(const char* sn);
    int set_manufacturer(const char* manufacturer);
    int set_model(const char* model);
    int set_firmware_version(const char* firmware);
    
    // 新增SMART信息查询方法
    int get_smart_attribute(int attribute_id, int* current, int* worst, int* threshold, int* raw_value) const;
    int set_smart_attribute(int attribute_id, int current, int worst, int threshold, int raw_value);
    int get_smart_status(int* overall_status) const;
    int get_smart_temperature(int* temperature) const;
    int get_smart_power_on_hours(int* hours) const;
    int get_smart_reallocated_sectors(int* count) const;
    
private:
    int fd_;
    std::size_t size_;
    bool powered_on_;
    char* file_path_;
    
    // 新增磁盘信息字段
    char serial_number_[64];
    char manufacturer_[64];
    char model_[64];
    char firmware_version_[32];
    
    // 新增SMART信息字段
    struct SmartAttribute {
        int current;
        int worst;
        int threshold;
        int raw_value;
    };
    SmartAttribute smart_attributes_[256];  // 支持256个SMART属性
    int smart_overall_status_;
    int smart_temperature_;
    int smart_power_on_hours_;
    int smart_reallocated_sectors_;
};

#endif // DISK_SIMULATOR_H 